LFS_SOURCES=$(LFS)/sources
LFS_TOOLS=$(LFS)/tools
LFS_BUILD=$(LFS)/build
LFS_LOCAL=$(LFS)/local

clean-all: clean-build clean-local clean-tools

clean-tools:
	rm -rf $(LFS)/tools/*

clean-build:
	rm -rf $(LFS)/build/*

clean-local:
	rm -rf $(LFS)/local/*

temp-binutils-pass1: clean-build clean-tools
	mkdir -p build/binutils-build
	tar xf sources/binutils-2.20.tar.bz2 -C build
	cd build/binutils-build && \
		../binutils-2.20/configure \
			--target=$(LFS_TGT) --prefix=/tools \
			--disable-nls --disable-werror && \
		make && \
		$(LFS)/temp-binutils-lib64.sh && \
		make install

temp-gmp: clean-build
	rm -rf local/gmp
	tar xf sources/gmp-5.0.0.tar.bz2 -C build
	cd build/gmp-5.0.0 && \
		./configure \
			--prefix=$(LFS)/local/gmp && \
		make && \
		make install

temp-mpfr: clean-build
	rm -rf local/mpfr
	tar xf sources/mpfr-2.4.2.tar.bz2 -C build
	cd build/mpfr-2.4.2 && \
		./configure \
			--prefix=$(LFS)/local/mpfr \
			--with-gmp=$(LFS)/local/gmp && \
		make && \
		make install

temp-gcc-pass1: clean-build
	mkdir -p build/gcc-build
	tar xf sources/gcc-4.4.3.tar.bz2 -C build
	cd build/gcc-build && \
		LD_LIBRARY_PATH=$(LFS)/local/gmp/lib:$(LFS)/mpfr/lib \
		../gcc-4.4.3/configure \
			--target=$(LFS_TGT) --prefix=/tools \
			--with-gmp=$(LFS)/local/gmp \
			--with-mpfr=$(LFS)/local/mpfr  \
			--disable-nls --disable-shared --disable-multilib \
			--disable-decimal-float --disable-threads \
			--disable-libmudflap --disable-libssp \
			--disable-libgomp --enable-languages=c && \
		make && \
		make install && \
		ln -vs libgcc.a `$(LFS_TGT)-gcc -print-libgcc-file-name | \
			sed 's/libgcc/&_eh/'`

temp-linux: clean-build
	tar xf sources/linux-2.6.32.8.tar.bz2 -C build
	cd build/linux-2.6.32.8 && \
		make mrproper && \
		make headers_check && \
		make INSTALL_HDR_PATH=dest headers_install && \
		cp -rv dest/include/* /tools/include

temp-glibc: clean-build
	mkdir -p build/glibc-build
	tar xf sources/glibc-2.11.1.tar.bz2 -C build
	cd build/glibc-build && \
		$(LFS)/temp-glibc-cflags.sh && \
		../glibc-2.11.1/configure \
			--prefix=/tools \
			--host=$(LFS_TGT) \
			--build=$(../glibc-2.11.1/scripts/config.guess) \
			--disable-profile --enable-add-ons \
			--enable-kernel=2.6.18 \
			--with-headers=/tools/include \
			libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes && \
		make && \
		make install

chain-adjust:
	$(LFS)/chain-adjust.sh

chain-test:
	cd $(LFS_BUILD) && \
		echo 'main(){}' > dummy.c && \
		$(LFS_TGT)-gcc -B$(LFS_TOOLS)/lib dummy.c && \
		readelf -l a.out | grep ': /tools'

binutils-second: clean-build
	mkdir -p $(LFS_BUILD)/binutils-build
	cd $(LFS_BUILD) && tar xf $(LFS_SOURCES)/binutils-2.20.tar.bz2
	cd $(LFS_BUILD)/binutils-build && \
		CC="$(LFS_TGT)-gcc -B$(LFS_TOOLS)/lib/" \
		AR=$(LFS_TGT)-ar \
		RANLIB=$(LFS_TGT)-ranlib \
		../binutils-2.20/configure --prefix=$(LFS_TOOLS) \
			--disable-nls --with-lib-path=$(LFS_TOOLS)/lib && \
		make && \
		make install && \
		make -C ld clean && \
		make -C ld LIB_PATH=/usr/lib:/lib && \
		cp -v ld/ld-new $(LFS_TOOLS)/bin

temp-gcc-pass2: clean-build
	mkdir -p build/gcc-build
	tar xf $(LFS)/sources/gcc-4.4.3.tar.bz2 -C build
	cd build/gcc-4.4.3 && $(LFS)/temp-gcc-pass2-patch.sh
	cd build/gcc-build && \
		CC="$(LFS_TGT)-gcc -B/tools/lib/" \
		AR=$(LFS_TGT)-ar \
		RANLIB=$(LFS_TGT)-ranlib \
		../gcc-4.4.3/configure \
			--prefix=/tools \
			--with-local-prefix=/tools \
			--with-gmp=$(LFS)/local/gmp \
			--with-mpfr=$(LFS)/local/mpfr  \
			--enable-clocale=gnu \
			--enable-shared --enable-threads=posix \
			--enable-__cxa_atexit --enable-languages=c,c++ \
			--disable-libstdcxx-pch --disable-multilib \
			--disable-bootstrap && \
		make && \
		make install && \
		ln -vs gcc /tools/bin/cc

temp-tcl: clean-build
	tar xf sources/tcl8.5.8-src.tar.gz -C build
	cd build/tcl8.5.8/unix && \
		./configure --prefix=/tools && \
		make && \
		TZ=UTC make test && \
		make install && \
		chmod -v u+w /tools/lib/libtcl8.5.so && \
		make install-private-headers && \
		ln -sv tclsh8.5 /tools/bin/tclsh

temp-expect: clean-build
	tar xf sources/expect-5.43.0.tar.gz -C build
	cd build/expect-5.43 && \
		patch -Np1 -i $(LFS)/sources/expect-5.43.0-spawn-1.patch && \
		patch -Np1 -i $(LFS)/sources/expect-5.43.0-tcl_8.5.5_fix-1.patch && \
		cp -v configure configure.orig && \
		sed 's:/usr/local/bin:/bin:' configure.orig > configure && \
		./configure --prefix=/tools --with-tcl=/tools/lib \
			--with-tclinclude=/tools/include --with-x=no && \
		make && \
		make test && \
		make SCRIPTS="" install

temp-dejagnu: clean-build
	tar xf sources/dejagnu-1.4.4.tar.gz -C build
	cd build/dejagnu-1.4.4 && \
		./configure --prefix=/tools && \
		make install && \
		make check

temp-ncurses: clean-build
	tar xf sources/ncurses-5.7.tar.gz -C build
	cd build/ncurses-5.7 && \
		./configure --prefix=/tools --with-shared \
			-without-debug --without-ada --enable-overwrite && \
		make && \
		make install

temp-bash: clean-build
	tar xf sources/bash-4.1.tar.gz -C build
	cd build/bash-4.1 && \
		./configure --prefix=/tools --without-bash-malloc && \
		make && \
		make tests && \
		make install && \
		ln -vs bash /tools/bin/sh

temp-bzip2: clean-build
	tar xf sources/bzip2-1.0.5.tar.gz -C build
	cd build/bzip2-1.0.5 && \
		make && \
		make PREFIX=/tools install

temp-coreutils: clean-build
	tar xf sources/coreutils-8.4.tar.gz -C build
	cd build/coreutils-8.4 && \
		./configure --prefix=/tools --enable-install-program=hostname && \
		make && \
		make RUN_EXPENSIVE_TESTS=yes check && \
		make install && \
		cp -v src/su /tools/bin/su-tools

temp-diffutils: clean-build
	tar xf sources/diffutils-2.8.1.tar.gz -C build
	cd build/diffutils-2.8.1 && \
		./configure --prefix=/tools && \
		make && \
		make install

temp-findutils: clean-build
	tar xf sources/findutils-4.4.2.tar.gz -C build
	cd build/findutils-4.4.2 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-gawk: clean-build
	tar xf sources/gawk-3.1.7.tar.bz2 -C build
	cd build/gawk-3.1.7 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-gettext: clean-build
	tar xf sources/gettext-0.17.tar.gz -C build
	cd build/gettext-0.17/gettext-tools && \
		./configure --prefix=/tools --disable-shared && \
		make -C gnulib-lib && \
		make -C src msgfmt && \
		cp -v src/msgfmt /tools/bin

temp-grep: clean-build
	tar xf sources/grep-2.5.4.tar.bz2 -C build
	cd build/grep-2.5.4 && \
		./configure --prefix=/tools \
			--disable-perl-regexp \
			--without-included-regex && \
		make && \
		make check && \
		make install

temp-gzip: clean-build
	tar xf sources/gzip-1.4.tar.gz -C build
	cd build/gzip-1.4 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-m4: clean-build
	tar xf sources/m4-1.4.13.tar.bz2 -C build
	cd build/m4-1.4.13 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-make: clean-build
	tar xf sources/make-3.81.tar.bz2 -C build
	cd build/make-3.81 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-patch: clean-build
	tar xf sources/patch-2.6.1.tar.bz2 -C build
	cd build/patch-2.6.1 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-perl: clean-build
	tar xf sources/perl-5.10.1.tar.bz2 -C build
	cd build/perl-5.10.1 && \
		patch -Np1 -i $(LFS)/sources/perl-5.10.1-libc-1.patch && \
		sh Configure -des -Dprefix=/tools \
			-Dstatic_ext='Data/Dumper Fcntl IO POSIX' && \
		make perl utilities ext/Errno/pm_to_blib && \
		cp -v perl pod/pod2man /tools/bin && \
		mkdir -pv /tools/lib/perl5/5.10.1 && \
		cp -Rv lib/* /tools/lib/perl5/5.10.1

temp-sed: clean-build
	tar xf sources/sed-4.2.1.tar.bz2 -C build
	cd build/sed-4.2.1 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-tar: clean-build
	tar xf sources/tar-1.22.tar.bz2 -C build
	cd build/tar-1.22 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install

temp-textinfo: clean-build
	tar xf sources/texinfo-4.13a.tar.gz -C build
	cd build/texinfo-4.13 && \
		./configure --prefix=/tools && \
		make && \
		make check && \
		make install
















